/**
 * Created by Administrator on 2019/7/31.
 */
"use strict";
const requireEx=require('yi-require');
const qr = require('qr-image')

const handler = (req,res,next)=>{
    let qrId = req.query.qrId;
    let expireMinutes = req.query.expireMinutes;
    let qrCodeType = req.query.qrCodeType;

    req.redis.setValueAndExpire('QrCode'+qrCodeType+':'+qrId,'',expireMinutes * 60,(e,r)=>{
        if(e)
            return res.reply({code:5001,message:'获取二维码失败'});
        else{
            let qrCodeObj={
                qrId:qrId,
                expireMinutes:expireMinutes,
                qrCodeType:qrCodeType
            }
            let img = qr.image(JSON.stringify(qrCodeObj),{size :6});
            res.writeHead(200, {'Content-Type': 'image/png'});
            img.pipe(res);
        }
    });

}

module.exports = {
    open:true,
    description: '获取二维码图片',
    handler: handler
};
